import java.util.Arrays;

public class Test {
    public static void sortOddEven(int[] array) {
        int i = 0;
        int j = array.length - 1;
        while(i < j) {
            while(i < j && array[i] % 2 != 0) {
                i++;
            }
            while(i < j && array[j] % 2 ==0) {
                j--;
            }
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6};
        sortOddEven(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main9(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6};
        int j = 0;
        for(int i = 0; i < array.length; i++) {
            if(array[i] % 2 == 0) {
                int tmp = array[i];
                array[i] = array[array.length - 1 - j];
                array[array.length - 1 - i] = tmp;
                j++;
            }
        }
        System.out.println(Arrays.toString(array));
    }
    public static void transform(int[] arr) {
//        int[] str = Arrays.copyOf(arr, arr.length);
//        arr = str;
//        int[] str = Arrays.copyOfRange(arr, 3, 4);
//        arr = str;
//        int[] str = new int[arr.length];
//        System.arraycopy(arr, 1, str, 1, arr.length - 1);
//        arr = str;
    }
    public static void main8(String[] args) {
        int[] arr = {1, 2, 3};
        transform(arr);

        System.out.println(Arrays.toString(arr));
    }
    public static void main7(String[] args) {
        //不规则数组
        int[][] array = new int[3][];
        array[0] = new int[3];
        array[1] = new int[2];
        array[2] = new int[1];
        System.out.println(Arrays.deepToString(array));
//        int[] arr = new int[2];
//        arr = new int[]{1, 2, 3};
//        for(int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i]);
//        }
    }
    public static void main6(String[] args) {
        int[][] array = new int[2][];
        for(int i = 0; i < array.length; i++) {
            //空指针异常
            for(int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]);
            }
        }
    }
    public static void main5(String[] args) {
        int[][] arr = new int[2][5];
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

        for(int[] arr1 : arr) {
            for(int x : arr1) {
                System.out.print(x + " ");
            }
            System.out.println();
        }
    }
    public static void main4(String[] args) {
        int[][] arr = new int[2][4];
        System.out.println(arr[0]);
        System.out.println(Arrays.toString(arr[0]));
        System.out.println(arr[1]);
        System.out.println(Arrays.toString(arr[1]));
        System.out.println(Arrays.deepToString(arr));
    }
    public static void main3(String[] args) {
        int[][] arr = new int[2][3];
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < 3; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void main2(String[] args) {
    //二位数组的定义
        int[][] arr1 = {{1, 3, 4}, {1, 3, 5}};
        int[][] arr2 = new int[][]{{1, 3, 4}, {1, 3, 5}};
        int[][] arr3 = new int[2][3];
    }
    public static void bubblesort(int[] arr) {
        for(int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for(int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j] > arr[j + 1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                    flag = true;
                }
                }
            if(!flag) {
                return;
            }
        }
    }
    public static void main1(String[] args) {
        int[] arr = {1, 2, 4, 64, 345, 555, 45, 3456, 22222};
        bubblesort(arr);

        System.out.println(Arrays.toString(arr));
    }
}
